package expressions;

import values.Value;
import values.Array;
import base.AST;
import base.Environment;

public class ArrayExpr implements Expression {

	private AST[] items;

	public ArrayExpr(AST[] items) {
		// assert index instanceof Expression || index instanceof Integer;

		this.items = items;
	}

	public Value eval(Environment env) throws BadExpressionException {

		Value[] values = new Value[this.items.length];

		for (int i = 0; i < values.length; i++) {

			if (items[i] instanceof Expression)
				values[i] = ((Expression) items[i]).eval(env);
			else if (items[i] instanceof Value)
				values[i] = (Value) items[i];
			else
				throw new BadExpressionException(
						"Values in array must be expressions or values");

		}

		return new Array(values);

	}

}
